/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-08-14     RiceChen     first version
 */

#ifndef __DRV_USART_H__
#define __DRV_USART_H__

#include "board.h"
#include "hal_uart.h"
#include "hal_gpio.h"
#include "hal_rcc.h"

#ifdef __cplusplus
extern "C" {
#endif

struct mm32_uart_config
{
    const char *name;
    GPIO_Type *rx_gpiox;
    int rx_rcc_clock;
    int rx_pin;
    int rx_gpio_af;
    GPIO_Type *tx_gpiox;
    int tx_rcc_clock;
    int tx_pin;
    int tx_gpio_af;
    
    int uart_rcc_clock;
    int clock_freq;
    UART_Type *uartx;
    IRQn_Type irq_type;
};

struct mm32_uart
{
    UART_Init_Type handle;
    struct mm32_uart_config *config;

    rt_uint16_t dma_flag;
    struct rt_serial_device serial;
};

#if defined(BSP_USING_UART1)
#ifndef UART1_CONFIG
#define UART1_CONFIG                                \
    {                                               \
        .name           = "uart1",                  \
        .rx_gpiox       = GPIOB,                    \
        .rx_rcc_clock   = RCC_AHB1_PERIPH_GPIOB,    \
        .rx_pin         = GPIO_PIN_7,               \
        .rx_gpio_af     = GPIO_AF_7,                \
        .tx_gpiox       = GPIOB,                    \
        .tx_rcc_clock   = RCC_AHB1_PERIPH_GPIOB,    \
        .tx_pin         = GPIO_PIN_6,               \
        .tx_gpio_af     = GPIO_AF_7,                \
        .uart_rcc_clock = RCC_APB2_PERIPH_UART1,    \
        .clock_freq     = CLOCK_APB2_FREQ,          \
        .uartx          = UART1,                    \
        .irq_type       = UART1_IRQn,               \
    }
#endif /* UART1_CONFIG */
#endif /* BSP_USING_UART1 */

#ifdef __cplusplus
}
#endif

#endif
